﻿#include "DirectoryModel.h"

QDirectoryModel::QDirectoryModel(QObject *parent)
	: QFileSystemModel(parent)
{
	setRootPath(QDir::rootPath());
	// 设置为只读
	setReadOnly(true);

	setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);

	sort(0);
}

QDirectoryModel::~QDirectoryModel()
{

}

int QDirectoryModel::columnCount(const QModelIndex &parent) const
{
	return 1;
}

QVariant QDirectoryModel::headerData(int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/) const
{
	if (role != Qt::DisplayRole)
	{
		return QVariant();
	}

	if (orientation == Qt::Horizontal)
	{
		switch (section)
		{
		case 0:
			return "Directory";
		}
	}

	return QFileSystemModel::headerData(section, orientation, role);
}
